import router from '@ohos.router';
import RdbStoreModel from '../../../model/RdbStoreModel.js'
import GameModel from '../../../model/GameModel.js'

const TAG = '[topPage]'

export default {
    data: {
        title: "排行榜",
        gameEasyInfos: [],
        gameMediumInfos: [],
        gameDifficultyInfos: [],
        gameFightInfos: [],
        curNickName: '',
        RdbStoreModel: new RdbStoreModel(),
        GameModel: new GameModel(),
        model: [],
        curGameModel: 0
    },

    onInit() {
        this.curNickName = router.getParams().nick_name;
        console.info(`${TAG} curNickName:${this.curNickName}`);
        this.curGameModel = this.GameModel.MODEL_EASY;
        this.model = [
            this.GameModel.MODEL_EASY,
            this.GameModel.MODEL_MEDIUM,
            this.GameModel.MODEL_DIFFICULTY,
            this.GameModel.MODEL_FIGHT,
        ];

    },

    onShow() {
        // 获取数据库中的数据
        this.queryContact();
    },

    modelChange(data) {
        console.info(`${TAG} Tab index:${data.index}`);
        this.curGameModel = this.model[data.index];
        this.queryContact();
    },

    queryContact() {
        let self = this;
//        if (this.curGameModel === this.GameModel.MODEL_FIGHT) {
//            this.RdbStoreModel.queryFightValue(this.curNickName, (contactList) => {
//                self.gameFightInfos = contactList;
//            })
//        } else {
            this.RdbStoreModel.queryValueByModule(this.curNickName, this.curGameModel, (contactList) => {
                console.info(`${TAG} query Contact:${contactList.length}`);
                if (contactList.length > 0) {
                    switch (self.curGameModel) {
                        case self.GameModel.MODEL_EASY:
                        {
                            self.gameEasyInfos = contactList;
                            break;
                        }
                        case self.GameModel.MODEL_MEDIUM:
                        {
                            self.gameMediumInfos = contactList;
                            break;
                        }
                        case self.GameModel.MODEL_DIFFICULTY:
                        {
                            self.gameDifficultyInfos = contactList;
                            break;
                        }
                        default:
                            {
                                break;
                            }
                    }
                }
            });
//        }
    },

    onBack() {
        router.back();
    }

}
